//
//  MyVC.m
//  爱鲜蜂(郭少乾)
//
//  Created by GuoDeJin on 2016/11/19.
//  Copyright © 2016年 GuoDeJin. All rights reserved.
//

#import "BQMineViewController.h"
#import "Masonry.h"
#import "tabV.h"
#import "orderView.h"
#import "imageV.h"
#import "myOrderTableVc.h"
#import "BQFeedbackController.h"
#import "AXFCouponController.h"
#import "AXFMessageController.h"
#import "BQGoodsAddressController.h"
#import "BQAssistController.h"
#import "BQSetViewController.h"
#import "BQShopStoreUp.h"
#import "BQLogInVc.h"
#import "SVProgressHUD.h"
#import <UMSocialCore/UMSocialCore.h>
#import "NSAttributedString+CZAdditon.h"
static NSString *cellID = @"cellID";

@interface BQMineViewController ()<orderViewDelegate,imageVDelegate,cellPushDelegater>

@property (nonatomic,weak) imageV *iconView;

@end

@implementation BQMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //接收登录成功的信息
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didLoadSucess:) name:@"loadSucess" object:nil];
    //接收退出登录发来的通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(exitLogin) name:@"exitLogin" object:nil];
    
    [self setupUI];
    
}
- (void)didLoadSucess:(NSNotification*)no
{
    _flag = YES;
    
//    [self.iconView.PhoneNumButton setTitle:@"aaaaaaa" forState:UIControlStateNormal];
    
    NSString *phoneNum = (NSString*)no.object;
    
    self.iconView.phoneNum = phoneNum;

    
}

- (void)exitLogin{
    
    _flag = NO;
    
    self.iconView.phoneNum = @"未登录";
    
}

//设置UI界面
- (void)setupUI{
    
    
    //上面图片
    imageV *imagV = [[imageV alloc]init];
    imagV.delegate = self;
    [self.view addSubview:imagV];
    
    self.iconView = imagV;
    [imagV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self.view);
        make.height.offset(160);
        
    }];
    
    //订单view
    orderView *orderV = [[orderView alloc]init];
    orderV.delegate = self;
    [self.view addSubview:orderV];
    
    [orderV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(imagV.mas_bottom);
        make.left.right.equalTo(self.view);
        make.height.offset(60);
        
    }];

    //下面tableVie
    tabV *tab = [[tabV alloc]init];
    tab.delegate = self;
    [self.view addSubview:tab];
    
    [tab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(orderV.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
        
    }];
 
    
}

//视图将要被移除   显示导航条
- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}
//视图将要显示  隐藏导航条
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}

#pragma mark - 我的订单,优惠券,我的消息 的按钮跳转代理方法
- (void)pushToOtherView:(UIButton *)btn
{
    
    //tag 1 == 我的订单
    //tag 2 == 优惠券
    //tag 3 == 我的消息
    
    myOrderTableVc *tbVc = [[myOrderTableVc alloc]init];
    
    AXFCouponController *couponVC = [[AXFCouponController alloc]init];
    
    AXFMessageController *messageVC = [[AXFMessageController alloc]init];
    
    //tag 1 == 我的订单
    if(btn.tag == 1){
        
        [self.navigationController pushViewController:tbVc animated:YES];
    }
    //tag 2 == 优惠券
    else if(btn.tag == 2)
    {
        [self.navigationController pushViewController:couponVC animated:YES];
    }
    else
    {
        [self.navigationController pushViewController:messageVC animated:YES];
    }
}

#pragma mark - 我的界面下方cell的点击跳转代理方法
- (void)cellPushController:(UIView *)tabV withIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        NSLog(@"我的收货地址");
        BQGoodsAddressController * addRessController = [[BQGoodsAddressController alloc]init];
        [self.navigationController pushViewController:addRessController animated:YES];
        
    }else if(indexPath.section == 0 && indexPath.row == 1){
        NSLog(@"店铺收藏");
        BQShopStoreUp *shopVc = [[BQShopStoreUp alloc]init];
        [self.navigationController pushViewController:shopVc animated:YES];
        
    }else if(indexPath.section == 1 && indexPath.row == 0){
        NSLog(@"把爱鲜蜂分享给朋友");
        [self tanChuang];
    }else if(indexPath.section == 2 && indexPath.row == 0){
        NSLog(@"客服帮助");
        BQAssistController *keFuBangZhuTabVc = [[BQAssistController alloc]init];
        [self.navigationController pushViewController:keFuBangZhuTabVc animated:YES];
    }else if(indexPath.section == 2 && indexPath.row == 1){
       
    BQFeedbackController * fdVc = [[BQFeedbackController alloc]init];
   
    [self.navigationController pushViewController:fdVc animated:YES];
    
      
    }
    

}
#pragma mark - 把爱鲜蜂分享给朋友
- (void)tanChuang{
    
    //初始化AlertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"分享到" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    
    //添加按钮
    [alertController addAction:[UIAlertAction actionWithTitle:@"微信好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //微信好友的点击事件
        [self shareWithIndex:1];
        
    }]];
    
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"微信朋友圈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //微信朋友圈的点击事件
        [self shareWithIndex:2];

        
    }]];
    
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //新浪微博的点击事件
        [self shareWithIndex:0];

        
    }]];
    
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"QQ空间" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //QQ空间的点击事件
        [self shareWithIndex:5];

        
    }]];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        //取消
        
    }]];
    
    //模态切换显示表单
    [self presentViewController:alertController animated:YES completion:nil];
  
}


#pragma mark - 头像 点击跳转代理方法
- (void)touXiangPush{
    
    NSLog(@"头像");
    if (_flag == 0 )
    {
        
        BQLogInVc *logVc = [[BQLogInVc alloc]init];
        
        
        [self.navigationController pushViewController:logVc animated:YES];

    }else{
        
        [SVProgressHUD showWithStatus:@"您已经登录了"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [SVProgressHUD dismiss];
        });
        
        
    }
    
    
}


#pragma mark - 设置按钮 点击跳转的代理方法
-(void)sheZhiPush{
    
    BQSetViewController * setVC = [[BQSetViewController alloc]init];
    [self.navigationController pushViewController:setVC animated:YES];
    NSLog(@"设置");
    
}


#pragma mark  根据标号   分享到不同的平台
- (void)shareWithIndex:(NSInteger)index
{
    
    //    UMSocialPlatformType_Sina  0
    //    UMSocialPlatformType_WechatSession      = 1, //微信聊天
    //    UMSocialPlatformType_WechatTimeLine     = 2,//微信朋友圈
    //    UMSocialPlatformType_WechatFavorite     = 3,//微信收藏
    //    UMSocialPlatformType_QQ                 = 4,//QQ聊天页面
    //    UMSocialPlatformType_Qzone              = 5,//qq空间
    
    NSString *content = [NSString stringWithFormat:@"Miracles sometimes occur, but one has to work terribly for them. （ C. Weizmann ）"];
    
    UMSocialMessageObject *manager = [UMSocialMessageObject messageObject];
    manager.text = content;
    if (index == 0) {
        
        //创建网页内容对象
        //        UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"分享标题" descr:@"分享内容描述" thumImage:[UIImage imageNamed:@"icon"]];
        //        //设置网页地址
        //        shareObject.webpageUrl =@"http://mobile.umeng.com/social";
        //创建图片内容对象
        UMShareImageObject *shareImageObject = [[UMShareImageObject alloc] init];
        //如果有缩略图，则设置缩略图
//        [shareImageObject setShareImage:_goodModel.img];
        manager.shareObject = shareImageObject;
    }
    
    
    [[UMSocialManager defaultManager] shareToPlatform:index messageObject:manager currentViewController:self completion:^(id result, NSError *error) {
        if (!error) {
            NSLog( @"分享成功");
        }
    }];
    
}



@end
